package com.cusc.module_login.mvvm.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.cusc.lib_api.bean.login.MainBean;
import com.cusc.lib_api.bean.login.response.LoginInfoBean;
import com.cusc.module_login.mvvm.model.LoginNetRegister;
import com.cusc.module_login.utils.ModulePermission;
import com.tcgroup.phone.base_core.framework.mvvm.viewmodel.BaseRefreshViewModel;
import com.tcgroup.phone.base_core.store.MmkvStore;
import com.tcgroup.phone.base_core.store.StoreKey;
import com.tcgroup.phone.base_core.utils.KLog;

import java.util.ArrayList;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/25.
 * 包名: com.cusc.module_login.vm
 * 类名: OSAndroidMvvm
 */
public class FunctionViewModel extends BaseRefreshViewModel<MainBean,LoginNetRegister> {

    LoginInfoBean mLoginInfoBean;
    ArrayList<MainBean> mMainBeanArrayList = new ArrayList<>();

    public FunctionViewModel(@NonNull Application application, LoginNetRegister netRegister) {
        super(application, netRegister);
        enableRefresh.set(false);
        enableLoadMore.set(false);
        mLoginInfoBean = MmkvStore.getInstance().getClassInfo(StoreKey.Module_Login.Login_Info, LoginInfoBean.class);
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void refreshData() {
        modulePermission();
        KLog.i("TAG","当前。。。");
       // postRefreshEvent(true);
        new Thread(() -> {
            //通过设置布尔值改变View
            try {
                //假设这里做了一个长时间的耗时操作
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //通过设置布尔值改变View
            isFinishRefresh.set(true);
        }).start();

   }

    @Override
    public void loadMore() {
        //postRefreshEvent(true);
        new Thread(() -> {
            //通过设置布尔值改变View
            try {
                //假设这里做了一个长时间的耗时操作
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //通过设置布尔值改变View
            isFinishLoadMore.set(true);
        }).start();
    }

    public void modulePermission(){
        mMainBeanArrayList.clear();
        mList.clear();
        ModulePermission.modulePermissionByGWC(mLoginInfoBean,mMainBeanArrayList);
        mMainBeanArrayList = MmkvStore.getInstance()
                .getListInfo(StoreKey.Module_Login.Module_List_01,MainBean.class);
        mList.addAll(mMainBeanArrayList);
    }

}
